<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0" />
  <meta http-equiv="X-UA-Compatible"
        content="ie=edge" />
  <title>Service服务</title>
</head>

<body>
  <div ng-app="myApp"
       ng-controller="customerCtrl"
       ng-init="num=0">
    <p>$location服务：{{ location }}</p>
    <p>$http服务：{{ myWecome }}</p>
    <p>$timeout：{{ myHead }}</p>
    <p>$interval：{{ time }}</p>
    <div>
      在过滤器中使用服务：
      <input type="number"
             ng-model="num"
             name=""
             id="">
      <p>转16进制：{{num | format}}</p>
    </div>
  </div>
  <script src="../lib/angular.1.7.8.js"></script>
  <script>
    var app = angular.module('myApp', [])
    app.controller('customerCtrl', function (
      $scope,
      $location,
      $http,
      $timeout,
      $interval,
      hexafy  // 自定义
    ) {
      console.log('TCL: $location', $location)
      $scope.location = $location.absUrl()
      $http
        .get('test.json')
        .then(resp => {
          console.log("TCL: resp", resp)
          $scope.myWecome = resp.data.data
        })
      $timeout(() => {
        $scope.myHead = 'Are you read?'
      }, 2000)

      $interval(() => {
        $scope.time = new Date().toLocaleTimeString()
      })
    })
    //  自定义服务
    app.service('hexafy', function () {
      this.ten2hex = function (value) {
        return value.toString(16)
      }
    })
    app.filter('format', function (hexafy) {
      return (value) => hexafy.ten2hex(value)
    })
  </script>
</body>

</html>
